<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>我的个人OJ系统</title>
    <style>
        * {
            margin: 0px;
            padding: 0px;
        }

        html,
        body {
            width: 100%;
            height: 100%;
            background-image: url("./images/indexbody.jpg");
            background-position: center;
            background-size: cover;
            overflow: hidden; /* 防止滚动条出现 */
        }

        canvas {
            position: fixed;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            pointer-events: none; /* 使canvas不阻挡鼠标事件 */
        }

        .container .navbar {
            width: 100%;
            height: 50px;
            background-color: black;
            overflow: hidden;
        }

        .container .navbar a {
            display: inline-block;
            width: 80px;
            color: white;
            font-size: large;
            line-height: 50px;
            text-decoration: none;
            text-align: center;
        }

        .container .navbar a:hover {
            background-color: green;
        }

        .container .navbar .login {
            float: right;
        }

        .container .content {
            width: 400px;
            margin: 0px auto;
            text-align: center;
            margin-top: 200px;
            background-color: rgba(27, 170, 195, 0.3);
        }

        .container .content .font_ {
            display: block;
            margin-top: 20px;
        }

        .container .content a {
            text-decoration: none;
            transition: transform 0.2s ease; /* 添加过渡效果 */
        }

        .container .content a:hover {
            transform: scale(1.1); /* 放大效果 */
        }

        .container .down {
            text-align: center;
        }
    </style>
</head>

<body>
    <canvas id="snowCanvas"></canvas>
    <div class="container">
        <div class="navbar">
            <a href="/">首页</a>
            <a href="/all_questions">题库</a>
            <a href="#">竞赛</a>
            <a href="/chat_page">讨论</a>
            <a href="#">求职</a>
        </div>
        <div class="content">
            <h1 class="font_">欢迎来到我的OnlineJudge平台</h1>
            <p class="font_">这是我个人独立开发的一个在线OJ平台</p>
            <a class="font_" href="/all_questions">点击我开始编程啦!</a>
        </div>
        <div class="down">
            <img class="snake" src="https://www.xygalgame.com/assets/snake-Light.svg" alt="动画">
        </div>
    </div>
    <script>
        const canvas = document.getElementById('snowCanvas');
        const ctx = canvas.getContext('2d');

        // 设置canvas尺寸
        canvas.width = window.innerWidth;
        canvas.height = window.innerHeight;

        const snowflakes = [];

        function createSnowflake() {
            const x = Math.random() * canvas.width;
            const y = Math.random() * canvas.height;
            const radius = Math.random() * 4 + 1; // 雪花半径 1 - 5
            snowflakes.push({ x, y, radius });
        }

        function updateSnowflakes() {
            for (let i = 0; i < snowflakes.length; i++) {
                const flake = snowflakes[i];
                flake.y += flake.radius / 2; // 控制下落速度
                if (flake.y > canvas.height) {
                    flake.y = 0; // 从顶部重新生成
                    flake.x = Math.random() * canvas.width; // 随机 x 坐标
                }
            }
        }

        function drawSnowflakes() {
            ctx.clearRect(0, 0, canvas.width, canvas.height); // 清除画布
            ctx.fillStyle = 'white';
            for (const flake of snowflakes) {
                ctx.beginPath();
                ctx.arc(flake.x, flake.y, flake.radius, 0, Math.PI * 2);
                ctx.fill();
            }
        }

        function animate() {
            updateSnowflakes();
            drawSnowflakes();
            requestAnimationFrame(animate);
        }

        for (let i = 0; i < 100; i++) { // 创建 100 颗雪花
            createSnowflake();
        }

        animate(); // 启动动画

        window.addEventListener('resize', () => {
            canvas.width = window.innerWidth;
            canvas.height = window.innerHeight;
        });
    </script>
</body>

</html>
